package com.masterclient.app.modules.order;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.masterclient.app.R;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.weigan.loopview.LoopView;
import com.weigan.loopview.OnItemSelectedListener;

import java.util.ArrayList;

/**
 * 作者：sean
 * 创建时间：2017/7/25 20:04
 * 功能说明：
 */

public class PaperInvoiceTypeDialog extends Dialog{


    private LoopView loopView;
    private TextView tv_cancle,tv_confirm;

    private String vat_type;

    public PaperInvoiceTypeDialog(@NonNull Context context,String vat_type) {
        super(context,R.style.MyDialog);
        this.vat_type = vat_type;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_paper_invoice_type);

        loopView = (LoopView) findViewById(R.id.loopView);
        tv_cancle = (TextView) findViewById(R.id.tv_cancle);
        tv_confirm = (TextView) findViewById(R.id.tv_confirm);
        ArrayList<String> list = new ArrayList<>();
        list.add("增值税普通发票");
        list.add("增值税专用发票");
        loopView.setItems(list);


        loopView.setListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                if(0 == index){
                    vat_type = "2";
                }else if(1 == index){
                    vat_type = "1";
                }
            }
        });

        if("1".equals(vat_type)){
            loopView.setInitPosition(1);
        }else if("2".equals(vat_type)){
            loopView.setInitPosition(0);
        }

        tv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        tv_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onConfirmListener!=null){
                    onConfirmListener.onConfirm(vat_type);
                }
                dismiss();
            }
        });
    }



    public void setOnConfirmListener(OnConfirmListener onConfirmListener) {
        this.onConfirmListener = onConfirmListener;
    }

    private OnConfirmListener onConfirmListener;

    public interface OnConfirmListener{
        public void onConfirm(String type);
    }


    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        window.setWindowAnimations(R.style.bottomShow);
        WindowManager.LayoutParams windowparams = window.getAttributes();
        window.setGravity(Gravity.BOTTOM);
        windowparams.width = ScreenUtils.getScreenWidth();
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowparams);
    }
}
